#import "SEGPaymethodlistv2Manager.h"

#if __has_include(<Commom/SEGModel.h>)
#import <Commom/SEGModel.h>
#else
#import "SEGModel.h"
#endif
#if __has_include(<Commom/SEGHTTPBusinessManager.h>)
#import <Commom/SEGHTTPBusinessManager.h>
#else
#import "SEGHTTPBusinessManager.h"
#endif

static id _PayMethodListV2Manager;
static dispatch_once_t onceToken;

@implementation SEGPaymethodlistv2Manager
#pragma mark - SINGLE----BEGIN----
+(instancetype)sharedManager{
    dispatch_once(&onceToken, ^{
        _PayMethodListV2Manager = [[self alloc] init];
    });
    return _PayMethodListV2Manager;
}

+(void)destroyResource{
    onceToken = 0;
    _PayMethodListV2Manager = nil;
}

#pragma mark - SINGLE----END----

#pragma mark - HTTP----BEGIN----

/**
 到家服务支付列表

 @author Sam
 
 返回结果：
 {
 "message": "获取成功!",
 "data": {
 "requestId": "38c0d85161c241f1b1841e5dc79e4580",
 "payeeId": "10",
 "mentodInfos": [{
 "id": "3",
 "name": "微信支付",
 "forwardUrl": "http://gamma.uhomecp.com/uhomecp-app/rest-api/v1/payment/forward/weixi.do",
 "iconUrl": "https://gammapic.uhomecp.com/2015/01/01/weixi@2x.png"
 }]
 },
 "code": "0"
 }
 */
-(void)requestHomeservicePaymethodlistv2Finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-app/homeservice-api/v1/order/payMethodList.json",nil];
    [self requestPaymethodlistv2WithUrlString:urlString parameters:nil finished:finished];
}

/**
 寻常汇获取支付列表
 月卡缴费获取支付列表
 费用缴纳账单获取支付列表

 @author Sam
 @param requestId requestId
 */
-(void)requestRestPaymethodlistv2WithRequestId:(NSString*)requestId finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if (requestId && requestId.length > 0) [params setValue:requestId forKey:@"requestId"];
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-app/rest-api/v1/payment/pollByPayMethodResult.json",nil];
    [self requestPaymethodlistv2WithUrlString:urlString parameters:params finished:finished];
}

/**
 自助洗车获取支付列表
 
 @author Sam
 */
-(void)requestFlashboxPaymethodlistv2Finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-app/flashbox-api/v1/payMethodList.json",nil];
    [self requestPaymethodlistv2WithUrlString:urlString parameters:nil finished:finished];
}

/**
 物业服务获取支付列表
 
 @author Sam
 @param communityId communityId
 */
-(void)requestRestPaymethodlistv2WithCommunityId:(NSString*)communityId finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if (communityId && communityId.length > 0) [params setValue:communityId forKey:@"communityId"];
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/order-user-api/rest-api/v5/order/paid/getPayMethodList.json",nil];
    [self requestPaymethodlistv2WithUrlString:urlString parameters:params finished:finished];
}

/**
 侨城汇获取支付列表
 
 @author Sam
 */
-(void)requestThirdOrderFinished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-app/v1/thirdOrder/payMethodList.json",nil];
    [self requestPaymethodlistv2WithUrlString:urlString parameters:nil finished:finished];
}

/**
 请求接口返回支付列表
 */
-(void)requestPaymethodlistv2WithUrlString:(NSString*)urlString parameters:(NSDictionary*)parameters finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    
    [SEGHTTPBusinessManager seg_requestWithMethod:GET URLString:urlString parameters:parameters completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed || result == nil) {
            finished(NO,nil,codeType,error.localizedDescription);
            return;
        }
        
        if (![result isKindOfClass:[NSDictionary class]]) {
            finished(NO,nil,codeType,error.localizedDescription);
            return;
        }
        
        self.PayMethodListV2 = [SEGPaymethodlistv2Model yy_modelWithDictionary:result];
        finished(YES,result,codeType,error.localizedDescription);
        return;
    }];
}

/**
 寻常汇获取支付列表requestId
 
 @author Sam
 @param site site
 */
-(void)requestIdForRestWithSite:(NSString*)site finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if (site && site.length > 0) [params setValue:site forKey:@"site"];
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-app/rest-api/v1/payment/payMethodList.json",nil];
    [self requestPaymethodlistv2RequestIdWithUrlString:urlString parameters:params finished:finished];
}

/**
 月卡缴费获取支付列表requestId
 
 @author Sam
 */
-(void)requestIdForParkingPayFinished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/car-payment-api/rest-api/v1/parkingPayRestApiController/getPayMethodList.json",nil];
    [self requestPaymethodlistv2RequestIdWithUrlString:urlString parameters:nil finished:finished];
}

/**
 费用缴纳账单获取支付列表requestId
 
 @author Sam
 */
-(void)requestIdForBillPaymentPayFinished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/uhomecp-app/rest-api/v1/billPayment/payMethodList.json",nil];
    [self requestPaymethodlistv2RequestIdWithUrlString:urlString parameters:nil finished:finished];
}

/**
 请求接口返回requestId
 */
-(void)requestPaymethodlistv2RequestIdWithUrlString:(NSString*)urlString parameters:(NSDictionary*)parameters finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:parameters completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed || result == nil) {
            finished(NO,nil,codeType,error.localizedDescription);
            return;
        }
        
        if (![[result valueForKey:@"data"] isKindOfClass:[NSString class]]) {
            finished(NO,nil,codeType,error.localizedDescription);
            return;
        }
        
        self.requestId = [result valueForKey:@"data"];
        finished(YES,result,codeType,error.localizedDescription);
        return;
    }];
}
#pragma mark - HTTP----END----

#pragma mark - GETTER----BEGIN----
-(SEGPaymethodlistv2Model *)PayMethodListV2{
    if (!_PayMethodListV2) {
        _PayMethodListV2 = [[SEGPaymethodlistv2Model alloc]init];
    }
    return _PayMethodListV2;
}

-(NSString *)requestId{
    if (!_requestId) {
        _requestId = [[NSString alloc]init];
    }
    return _requestId;
}
#pragma mark - GETTER----END----
@end
